package cn.e4j.modular.system.service.impl;

import cn.e4j.core.dto.impl.Dto;
import cn.e4j.modular.system.entity.SysLoadlog;
import cn.e4j.modular.system.entity.SysLoadlogError;
import cn.e4j.modular.system.mapper.SysLoadlogMapper;
import cn.e4j.modular.system.service.SysLoadlogService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yuan_rz
 * @since 2019-03-12
 */
@Service("sysLoadlogService")
public class SysLoadlogServiceImpl extends ServiceImpl<SysLoadlogMapper, SysLoadlog> implements SysLoadlogService {
    @Transactional(readOnly = true)
    public List<SysLoadlog> getListData(Page<Object> page, Dto dto) {
        List<SysLoadlog> listData = this.baseMapper.getListData(page, dto);
        return listData;
    }

    @Transactional(readOnly = true)
    public List<SysLoadlogError> getListDataDetail(Page<Object> page, Dto dto) {
        List<SysLoadlogError> listData = this.baseMapper.getListDataDetail(page, dto);
        return listData;
    }

    @Transactional
    public void addData(SysLoadlog sysLoadlog){
        //新增
        sysLoadlog.insert();
    }

    @Transactional
    public void editData(SysLoadlog sysLoadlog){
        sysLoadlog.updateById();
    }

    @Transactional
    public void deleteData(SysLoadlog sysLoadlog){
        delete(sysLoadlog);
    }

    @Transactional
    public void deleteDataBatch(List<SysLoadlog> sysLoadlogList){
        for(int i=0; i < sysLoadlogList.size(); i++){
            delete(sysLoadlogList.get(i));
        }
    }

    @Transactional
    public void deleteDataAll(){
        this.baseMapper.deleteDataAll();
        this.baseMapper.deleteDataAllDetail();

    }

    private void delete(SysLoadlog sysLoadlog){
        sysLoadlog.deleteById();
        this.baseMapper.deleteDataBatchDetail(sysLoadlog.getID());
    }
}
